using System;
using System.Text;

namespace iSonar.Lib.Utils {
  public class HexEncoder {
    private static char[] tab = new char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

    public static string Encode(byte[] buff, int off, int len) {
      return Encode(buff, off, len, "");
    }
    public static string Encode(byte[] buff, int off, int len, string separator) {
      StringBuilder _sb = new StringBuilder();
      int _len = (len >= 0) ? len : buff.Length;
      for (int i=off; i < _len; i++) {
        byte _b = buff[i];
        _sb.Append(tab[_b >> 4]);
        _sb.Append(tab[_b & 0x0f]);
        _sb.Append(separator);
      }
      return _sb.ToString();
    }

    HexEncoder() { }
  }
}
